package com.rd.student.jike.class2.lihongming.Solutions5;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Auther:Heinrich
 * @Date:2023/7/31-07-31-9:59
 * @Description:com.rd.student.jike.class2.lihongming.Solutions5
 * @version:1.0
 */

public class Question1_1 {
    public static String file = "..\\rd2304\\src\\com\\rd\\student\\jike\\class2\\lihongming\\Solutions5";

    public static void main(String[] args) throws IOException {
        String A = reader(file+"/A.txt");
        String B = reader(file+"/B.txt");
        String C = A.concat(B);
        File fileC = new File(file+"/C.txt");
        if (!fileC.exists()) {
            fileC.createNewFile();
        }
        writer(fileC,C,false);
    }

    public static String reader(String path) throws IOException {
        File file = new File(path);
        FileInputStream isRandom = new FileInputStream(file);
        byte[] pipe = new byte[(int) file.length()];
        isRandom.read(pipe);
        isRandom.close();
        return new String(pipe);
    }

    public static void writer(File file, String str, boolean concat) throws IOException {
        FileOutputStream os = new FileOutputStream(file, concat);
        byte[] pipe = str.getBytes();
        os.write(pipe);
        os.close();
    }
}
